package com.shanghaionstar.user;

import android.os.Bundle;
import android.view.View;

import com.onstar.cn.common.util.PreferencesUtls;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.onstar.cn.weight.more.CustomLineLayout;
import com.shanghaionstar.R;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.FinalConstants;
import com.shanghaionstar.weight.CommonProgressButton;
import com.shanghaionstar.weight.TopLayout;

/**
 * Created by 7828wc on 16/7/12.
 * 下发首选设置界面
 */
public class ChooseTBTODDFragment extends BaseFragment {
    @FindViewById
    private TopLayout top_layout;

    @FindViewById
    private CustomLineLayout preferred_tbt_layout, preferred_odd_layout;

    @FindViewById
    private CommonProgressButton btn_save;

    private boolean chooseTbt = false;
    private boolean chooseODD = false;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        btnBackClick(top_layout);

        if (isFirstLoad()) {
            if (PreferencesUtls.getInstance(getActivity()).getBoolean(FinalConstants.SharedPreferencesConfig.TBT_CHOOSE_SAVE, true)) {
                preferred_tbt_layout.setRightArrow(R.drawable.iccon_selected);
                preferred_odd_layout.setRightArrow(-1);
            } else {
                preferred_odd_layout.setRightArrow(R.drawable.iccon_selected);
                preferred_tbt_layout.setRightArrow(-1);
            }

            preferred_tbt_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.Setting_PreferTBT.getStringValue());
                    chooseTbt = true;
                    chooseODD = false;
//                    PreferencesUtls.getInstance(getActivity()).putBoolean(FinalConstants.SharedPreferencesConfig.TBT_CHOOSE_SAVE, true);
//                    PreferencesUtls.getInstance(getActivity()).putBoolean(FinalConstants.SharedPreferencesConfig.ODD_CHOOSE_SAVE, false);
                    preferred_tbt_layout.setRightArrow(R.drawable.iccon_selected);
                    preferred_odd_layout.setRightArrow(-1);
                }
            });
            preferred_odd_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    preferred_odd_layout.setRightArrow(R.drawable.iccon_selected);
                    preferred_tbt_layout.setRightArrow(-1);
                    BusinessUtil.sendReportByClickType(getActivity(), FunctionNameFindId.Setting_PreferODD.getStringValue());
                    chooseTbt = false;
                    chooseODD = true;
//                    PreferencesUtls.getInstance(getActivity()).putBoolean(FinalConstants.SharedPreferencesConfig.TBT_CHOOSE_SAVE, false);
//                    PreferencesUtls.getInstance(getActivity()).putBoolean(FinalConstants.SharedPreferencesConfig.ODD_CHOOSE_SAVE, true);
                }
            });
            btn_save.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    PreferencesUtls.getInstance(getActivity()).putBoolean(FinalConstants.SharedPreferencesConfig.TBT_CHOOSE_SAVE, chooseTbt);
                    PreferencesUtls.getInstance(getActivity()).putBoolean(FinalConstants.SharedPreferencesConfig.ODD_CHOOSE_SAVE, chooseODD);
                    back();
                }
            });
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.more_choose_tbt_odd;
    }
}
